//
// Created by xili on 2024/9/24 16:58.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int maxSubArray(vector<int> &nums) {
        int ans = nums[0];
        int n = nums.size();
        vector<int> dp(n);
        dp[0] = nums[0];
        for (int i = 1; i < n; i++) {
            //状态转移方程
            dp[i] = max(dp[i - 1], 0) + nums[i];
            ans = max(ans, dp[i]);
        }
        return ans;
    }
};